package org.achao.task;

/**
 * @author achao
 * @description task线程
 * @date 2023/9/27 0:37
 */
public class TaskRunner implements Runnable{
    private final String userName;
    private final long delay;

    public TaskRunner(String userName, long delay) {
        this.userName = userName;
        this.delay = delay;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(delay); // 等待指定的延迟时间
            // 任务执行逻辑，每2秒打印一次，持续10秒
            for (int i = 0; i < 5; i++) {
                System.out.println("hello " + userName);
                Thread.sleep(2000); // 每2秒打印一次
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
